package zero.tech.games.common;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import zero.tech.games.common.data.UserLastRoom;
import zero.tech.redis.cache.RedisUtil;
@Component
public class UserLastRoomUtil {
	@Autowired
	private RedisUtil redisUtil;
	public UserLastRoom insertOrUpdate(UserLastRoom userLastRoom) {
		redisUtil.hsetJson(RedisConsts.B_USER_LASTROOM,String.valueOf(userLastRoom.getUid()), userLastRoom);
		return userLastRoom;
	}
	
	public void delete(String playerid,String room_id) {
		UserLastRoom userLastRoom = getUserLastRoom(playerid);
		if(userLastRoom.getRoom_id().equals(room_id)) {
			deleteUserLastRoom(playerid);
			System.out.println("用户最后房间信息被清理了");
		}
	}

	public UserLastRoom getUserLastRoom(String playerid) {
		UserLastRoom userLastRoom=redisUtil.hgetJson(RedisConsts.B_USER_LASTROOM,playerid,UserLastRoom.class);
		return userLastRoom;
	}

	protected void deleteUserLastRoom(String playerid) {
		redisUtil.hdel(RedisConsts.B_USER_LASTROOM,playerid);
	}
	
}
